home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 502 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  40 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: [Q]Casting from struct->NULL.
  5. Date: Fri, 05 Jan 96 21:21:38 GMT
  6. Organization: none
  7. Message-ID: <820876898snz@genesis.demon.co.uk>
  8. References: <DKnDws.FG3.0.sheppard@torfree.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <DKnDws.FG3.0.sheppard@torfree.net>
  15.            bh332@freenet.toronto.on.ca "Karim Ladha" writes:
  16.  
  17. >
  18. >
  19. >Re: Casting.
  20. >
  21. >How is it possible to cast from a structure to NULL or something
  22. >equivalent? Currently, I have a function which either returns a
  23. >structure of type X; pointer, if success or 0L if fail. However,
  24. >trying to return 0L produces, "... Cannot cast from tagStruct
  25. >to long..." If you know of a solution, post. Greatly appreciated...
  26.  
  27. It is rare to pass actual structs as arguments or return values.
  28. Typically you pass a pointer to a struct. You then have the choice of
  29. setting it either to point to a struct or to NULL. Since you want the
  30. struct to exist in the caller once the called function has terminated
  31. a typical approach is to pass a pointer to a struct as an argument. Your
  32. called function can then modify the struct through the pointer and return
  33. a success/failure code in, say, an int return value.
  34.  
  35. -- 
  36. -----------------------------------------
  37. Lawrence Kirby | fred@genesis.demon.co.uk
  38. Wilts, England | 70734.126@compuserve.com
  39. -----------------------------------------
  40.